<?php
/**
 *   File functions:
 *   Show text in chat
 *
 *   @name                 : chatmsg.php                            
 *   @copyright            : (C) 2004,2005,2006 Vallheru Team based on Gamers-Fusion ver 2.5
 *   @author               : thindil <thindil@users.sourceforge.net>
 *   @version              : 1.0
 *   @since                : 03.02.2006
 *
 */

//
//
//       This program is free software; you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation; either version 2 of the License, or
//   (at your option) any later version.
//
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program; if not, write to the Free Software
//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// $Id$
require_once('includes/config.php');
require_once('includes/sessions.php');
require_once('libs/Smarty.class.php');

$smarty = new Smarty;
$smarty -> compile_check = true;

$stat = $db -> Execute("SELECT id, page, rank, style, graphic, miejsce FROM players WHERE email='".$_SESSION['email']."'");
/**
* Get the localization for game
*/
require_once("languages/pl/chatmsg.php");

/**
* Select style for chat
*/
if ($stat -> fields['graphic']) 
{
    $smarty -> template_dir = "./templates/".$player -> graphic;
    $smarty -> compile_dir = "./templates_c/".$player -> graphic;
    $strCss = '';
}   
    else
{
    $smarty -> template_dir = './templates';
    $smarty -> compile_dir = './templates_c';
    $strCss = $stat -> fields['style'];
}

if (!isset ($_GET['pokoj'])) 
{
exit;
}
if (isset ($_GET['pokoj'])) 
{
	if (!ereg("^[1-9][0-9]*$", $_GET['pokoj'])) 
	{
		exit;
	}

	$wypros = $db -> Execute("SELECT count(*) FROM spotk_wypr WHERE pokoj=".$_GET['pokoj']." AND kto=".$stat -> fields['id']);
	$ilewypros = $wypros -> fields['count(*)'];
	if ($ilewypros > 0 && $stat -> fields['id'] != 1) exit;
	$wypros -> Close();

	$sprawdz = $db -> Execute("SELECT count(*) from spotk_zapr WHERE (kto=".$stat -> fields['id']." OR kto='-1') AND pokoj=".$_GET['pokoj']);
	$ile = $sprawdz -> fields['count(*)'];
	if ($ile <= 0 && $stat -> fields['id'] != 1) exit;
	$sprawdz -> Close();

	$chat = $db -> SelectLimit("SELECT * FROM spotk WHERE pokoj=".$_GET['pokoj']." ORDER BY id DESC", 20);
	$e = $chat -> RecordCount();

	$arrtext = array();
	$arrauthor = array();
	$arrsenderid = array();
	$i = $e-1;
	$smarty -> assign ("Showid", 1);
	while (!$chat -> EOF) 
	{
		$text = wordwrap($chat -> fields['text'],50,"\n",1);
 		$arrtext[$i] = $text;
 		$arrczas[$i] = $chat -> fields['czas'];
		$arrauthor[$i] = $chat -> fields['user'];
		$arrsenderid[$i] = $chat -> fields['sender'];
		$chat -> MoveNext();
		$i = $i - 1;
	}
	$chat -> Close();
	if ($stat -> fields['page'] != 'Spotkanie z '.$_GET['pokoj']) $db -> Execute("UPDATE players SET page='Spotkanie z ".$_GET['pokoj']."' WHERE id=".$stat -> fields['id']);
}

$smarty -> assign ( array("Author" => $arrauthor, 
    "Text" => $arrtext, 
    "Czas" => $arrczas, 
    "Senderid" => $arrsenderid,
    "Charset" => CHARSET,
    "Thereis" => THERE_IS,
    "Texts" => TEXTS,
    "Cplayers" => C_PLAYERS,
    "Pokoj" => $_GET['pokoj'],
    "CSS" => $strCss));
$smarty -> display ('spotkmsgs.tpl');

?>
